package com.wframe.project.former.dataservices.sysman.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.hibernate.HibernateException;

import com.frame.database.JBaseDao;
import com.frame.database.JdataBean;

public class SysproDao extends JBaseDao{

	public SysproDao(){
		super("wb_sys_pro");
	}

	public void saveSysproVal(String code,String val) throws Exception{
		int n=getSession().update("update wb_sys_pro set val=? where code=?",new Object[]{val,code.toLowerCase()});
		if(n==0)
			getSession().update("insert into wb_sys_pro(val,code) values (?,?)",new Object[]{val,code.toLowerCase()});
	}
	public List<JdataBean> querySyspro() throws Exception{
		return getSession().query("select * from wb_sys_pro", null);
	}
	public List<JdataBean> queryAreatrad() throws Exception{
		return getSession().query("select * from wb_area_trad ",null);
	}
	public void saveAreatrad(JdataBean bean) throws Exception{
		if(StringUtils.isNotBlank(bean.getString("id"))){
			Map key=new HashMap();
			key.put("id", bean.getString("id"));
			getSession().update("wb_area_trad",bean.getDataMap(),key);
		}else getSession().save("wb_area_trad",bean.getDataMap());
	}
	public void delAreatrad(String id) throws HibernateException, Exception{
		getSession().delete("delete from wb_area_trad where id=?",new Object[]{id});
	}
	public JdataBean getAreatrad(String id) throws Exception{
		return getSession().getObject("select * from wb_area_trad where id=?", new Object[]{id});
	}
}
